package common.generate.config.generate.config;

import common.util.base.CommonUtil;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @author liubo
 *
 */
public class MyGenerateConfig{

	private Boolean controllerCreate;
	
	private Boolean serviceCreate;

	private Boolean serviceImplCreate;

	private Boolean daoCreate;

	private Boolean daoImplCreate;

	private Boolean mapperCreate;

	private Boolean xmlMapperCreate;
	
	private Boolean feignCreate;

	private Boolean feignFallbackCreate;

	private Boolean entityCreate;

	private Boolean listHtmlCreate;

	private Boolean editHtmlCreate;

	private Boolean listJsCreate;

	private Boolean editJsCreate;
	
	private Boolean entityEmeusCreate;

	private void initCreate(){
		Map<String,Boolean> createMap = new HashMap<String,Boolean>();
		Map<String, Field> fieldMap = CommonUtil.getFieldMap(this.getClass());
		for(String key:fieldMap.keySet()){
			if(key.endsWith("Create")){
				createMap.put(key, CommonUtil.getFieldValue(this, key));
			}
		}
		
		boolean isNull = true;
		boolean isTrue = false;
		boolean isFalse = false;

		for(String key:createMap.keySet()){
			Boolean create= createMap.get(key);
			if(CommonUtil.isNotEmpty(create)){
				if(true == create){
					isTrue = true;
				}else if(false == create){
					isFalse = true;
				}
			}
			
			if(isTrue || isFalse){
				isNull = false;
			}
		}


		for(String key:createMap.keySet()){
			Boolean create= createMap.get(key);
			if(isTrue){// true 存在, 优先等级 1
				if(CommonUtil.isEmpty(create)){
					createMap.put(key, false) ;
				}
				continue;
			}else if(isFalse){ // 当ture不存在, false 存在, 优先等级2
				if(CommonUtil.isEmpty(create)){
					createMap.put(key, true) ;
				}
				continue;
			}else if(isNull){// 全部是空 优先等级3
				createMap.put(key, true) ;
			}
		}
		for(String key:createMap.keySet()){
			CommonUtil.setFieldValue(this, key, (Boolean)createMap.get(key));
		}
	}
	public Boolean getEntityCreate() {
		if(CommonUtil.isEmpty(entityCreate)){
			initCreate();
		}
		return entityCreate;
	}
	public void setEntityCreate(Boolean entityCreate) {
		this.entityCreate = entityCreate;
	}

	public Boolean getControllerCreate() {
		if(CommonUtil.isEmpty(controllerCreate)){
			initCreate();
		}
		return controllerCreate;
	}
	public void setControllerCreate(Boolean controllerCreate) {
		this.controllerCreate = controllerCreate;
	}
	public Boolean getXmlMapperCreate() {
		if(CommonUtil.isEmpty(xmlMapperCreate)){
			initCreate();
		}
		return xmlMapperCreate;
	}
	public void setXmlMapperCreate(Boolean xmlMapperCreate) {
		this.xmlMapperCreate = xmlMapperCreate;
	}
	public Boolean getMapperCreate() {
		if(CommonUtil.isEmpty(mapperCreate)){
			initCreate();
		}
		return mapperCreate;
	}
	public void setMapperCreate(Boolean mapperCreate) {
		this.mapperCreate = mapperCreate;
	}
	
	public Boolean getEntityEmeusCreate() {
		if(CommonUtil.isEmpty(entityEmeusCreate)){
			initCreate();
		}
		return entityEmeusCreate;
	}
	public void setEntityEmeusCreate(Boolean entityEmeusCreate) {
		this.entityEmeusCreate = entityEmeusCreate;
	}
	
	public Boolean getDaoCreate() {
		if(CommonUtil.isEmpty(daoCreate)){
			initCreate();
		}
		return daoCreate;
	}
	public void setDaoCreate(Boolean daoCreate) {
		this.daoCreate = daoCreate;
	}
	
	public Boolean getDaoImplCreate() {
		if(CommonUtil.isEmpty(daoImplCreate)){
			initCreate();
		}
		return daoImplCreate;
	}
	public void setDaoImplCreate(Boolean daoImplCreate) {
		this.daoImplCreate = daoImplCreate;
	}
	
	public Boolean getServiceCreate() {
		if(CommonUtil.isEmpty(serviceCreate)){
			initCreate();
		}
		return serviceCreate;
	}
	public void setServiceCreate(Boolean serviceCreate) {
		this.serviceCreate = serviceCreate;
	}

	public Boolean getServiceImplCreate() {
		if(CommonUtil.isEmpty(serviceImplCreate)){
			initCreate();
		}
		return serviceImplCreate;
	}

	public void setServiceImplCreate(Boolean serviceImplCreate) {
		this.serviceImplCreate = serviceImplCreate;
	}

	public Boolean getListHtmlCreate() {
		if(CommonUtil.isEmpty(listHtmlCreate)){
			initCreate();
		}
		return listHtmlCreate;
	}

	public void setListHtmlCreate(Boolean listHtmlCreate) {
		this.listHtmlCreate = listHtmlCreate;
	}

	public Boolean getListJsCreate() {
		if(CommonUtil.isEmpty(listJsCreate)){
			initCreate();
		}
		return listJsCreate;
	}
	public void setListJsCreate(Boolean listJsCreate) {
		this.listJsCreate = listJsCreate;
	}
	
	public Boolean getEditJsCreate() {
		if(CommonUtil.isEmpty(editJsCreate)){
			initCreate();
		}
		return editJsCreate;
	}
	public void setEditJsCreate(Boolean editJsCreate) {
		this.editJsCreate = editJsCreate;
	}

	public Boolean getEditHtmlCreate() {
		if(CommonUtil.isEmpty(editHtmlCreate)){
			this.initCreate();
		}
		return editHtmlCreate;
	}
	public void setEditHtmlCreate(Boolean editHtmlCreate) {
		this.editHtmlCreate = editHtmlCreate;
	}
	public Boolean getFeignCreate() {
		if(CommonUtil.isEmpty(feignCreate)){
			this.initCreate();
		}
		return feignCreate;
	}
	public void setFeignCreate(Boolean feignCreate) {
		this.feignCreate = feignCreate;
	}
	public Boolean getFeignFallbackCreate() {
		if(CommonUtil.isEmpty(feignFallbackCreate)){
			this.initCreate();
		}
		return feignFallbackCreate;
	}
	public void setFeignFallbackCreate(Boolean feignFallbackCreate) {
		this.feignFallbackCreate = feignFallbackCreate;
	}

}